package zouran.service.impl;

import org.springframework.stereotype.Service;
import zouran.entity.IntensityLine;
import zouran.mapper.IntensityLineMapper;
import zouran.service.IntensityLineService;

import java.util.ArrayList;
import java.util.List;

/**
 * Author：zouran
 * Date：2023/3/31  20:59
 * Description:
 */
@Service
public class IntensityLineServiceImpl implements IntensityLineService {
    private final IntensityLineMapper intensityLineMapper;

    public IntensityLineServiceImpl(IntensityLineMapper intensityLineMapper) {
        this.intensityLineMapper = intensityLineMapper;
    }

    @Override
    public List<Double[]> getMultiLineStringWktToJson(String wkt) {
        String toTailWkt = wkt.substring(0, wkt.length() - 1);
        String[] strHead = toTailWkt.split("\\(", 2);
        String[] strList = strHead[1].split("\\),\\(");
        List<Double[]> list = new ArrayList<Double[]>();
        for (String value : strList) {
            String item = value.trim();
            item = item.substring(1, item.length() - 1);
            String[] items = item.split(",");
            for (String s : items) {
                String jItem = s.trim();
                String[] jItems = jItem.split(" ");
                Double[] listResult = new Double[]{
                        Double.parseDouble(jItems[0]),
                        Double.parseDouble(jItems[1])};
                list.add(listResult);
            }
        }
        return list;
    }

    @Override
    public List<IntensityLine> getIntensityLineByEarthquakeId(long id) {
        return intensityLineMapper.getIntensityLineByEarthquakeId(id);
    }
}
